using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/*
public static class OrdinanceManager {
	
	private static List<GameObject> missiles = new List<GameObject>();
	//also keep a map linking missiles to their targets
	private static Dictionary<int, List<GameObject>> targetsToMissiles = new Dictionary<int, List<GameObject>>();
	//private static List<GameObject> bullets = new List<GameObject>(); //not sure we need to track every bullet at the moment
	private static List<GameObject> miscRounds = new List<GameObject>();
	
	public static GameObject AddRound(Launcher launcher, Vector3 firingPoint, Quaternion heading, GameObject target)
	{
		GameObject newRound = (GameObject)GameObject.Instantiate(launcher.Ordinance, firingPoint, heading);
		switch (launcher.Type)
		{
			case Launcher.LauncherType.Missile:
			{
				missiles.Add(newRound);
				if(target != null)
				{
					//target-to-missile lists won't exist at first, so build them as needed
					int targetID = target.GetInstanceID();
					if(!targetsToMissiles.ContainsKey(targetID))
					{
						targetsToMissiles.Add(targetID, new List<GameObject>());
					}
					targetsToMissiles[targetID].Add(newRound);
				}
				break;
			}
			case Launcher.LauncherType.Bullet:
			{
				//bullets.Add(newRound);
				break;
			}
			default:
			{
				miscRounds.Add(newRound);
				break;
			}
		}
		return newRound;
	}
	
	public static GameObject AddRound(Launcher launcher, Vector3 firingPoint, Quaternion heading)
	{
		return AddRound(launcher, firingPoint, heading, null);
	}
	
	//removes and destroys a round from tracking
	public static void DestroyRoundOfType(Launcher.LauncherType type, GameObject ordinance)
	{
		switch (type)
		{
			case Launcher.LauncherType.Missile:
			{
				missiles.Remove(ordinance);
				//also find the target and remove from targetToMissile dictionary
				GameObject target = ordinance.GetComponent<MissileMovement>().Target;
				if(target != null)
				{
					int targetID = target.GetInstanceID();
					if(targetsToMissiles.ContainsKey(targetID))
					{
						targetsToMissiles[targetID].Remove(ordinance);
					}
				}
				break;
			}
			case Launcher.LauncherType.Bullet:
			{
				//ordinanceList = bullets;
				//break;
				return;
			}
			default:
			{
				miscRounds.Remove(ordinance);;
				break;
			}
		}
		GameObject.Destroy(ordinance);
	}
	
	public static void DestroyRound(GameObject ordinance)
	{
		//first search missiles, then misc rounds
		if(missiles.Contains(ordinance))
		{
			missiles.Remove(ordinance);
			//also find the target and remove from targetToMissile dictionary
			GameObject target = ordinance.GetComponent<MissileMovement>().Target;
			if(target != null)
			{
				int targetID = target.GetInstanceID();
				if(targetsToMissiles.ContainsKey(targetID))
				{
					targetsToMissiles[targetID].Remove(ordinance);
				}
			}
		}
		else if(miscRounds.Contains(ordinance))
		{
			miscRounds.Remove(ordinance);
		}
		GameObject.Destroy(ordinance);
	}
	
	public static List<GameObject> GetMissilesTrackingTarget(GameObject target)
	{
		if(target != null)
		{
			int targetID = target.GetInstanceID();
			if(!targetsToMissiles.ContainsKey(targetID))
			{
				targetsToMissiles[targetID] = new List<GameObject>();
			}
			return targetsToMissiles[targetID];
		}
		return new List<GameObject>();
	}
	
	public static GameObject FindMissileByTargetAndID(GameObject target, int msslID)
	{
		List<GameObject> msslList = GetMissilesTrackingTarget(target);
		if(msslList.Count > 0)
		{
			foreach(GameObject mssl in msslList)
			{
				if(msslID == mssl.GetInstanceID())
				{
					return mssl;
				}
			}
		}
		return null;
	}
}
*/